package com.yuwubao.hz_International.services.impl;

import com.yuwubao.hz_International.entities.ProceedsConfigEntity;
import com.yuwubao.hz_International.entities.repository.ProceedsConfigRepository;
import com.yuwubao.hz_International.services.ProceedsConfigService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yangyu on 2018/1/29.
 */
@Service
public class ProceedsConfigServiceImpl implements ProceedsConfigService {

    @Autowired
    private ProceedsConfigRepository proceedsConfigRepository;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<ProceedsConfigEntity> findAll() {
        return proceedsConfigRepository.findAll();
    }

    @Override
    public ProceedsConfigEntity save(ProceedsConfigEntity proceedsConfig) {
        return proceedsConfigRepository.save(proceedsConfig);
    }

    @Override
    public ProceedsConfigEntity update(ProceedsConfigEntity proceedsConfig) {
        ProceedsConfigEntity proceedsConfigEntity = proceedsConfigRepository.findOne(proceedsConfig.getId());
        if (proceedsConfigEntity != null) {
            ModelMapper model = new ModelMapper();
            ProceedsConfigEntity entity = model.map(proceedsConfig, ProceedsConfigEntity.class);
            return proceedsConfigRepository.save(entity);
        }
        return null;
    }
}
